/*
 * @Date: 2022-08-28 17:34:03
 * @LastEditors: czp
 * @LastEditTime: 2023-04-20 16:09:55
 */
import nav from "@/assets/json/nav.json";
import { defineStore } from "pinia";

import { IBaseState, INav } from "./interface/base";

export const useBaseStore = defineStore("base", {
	state: (): IBaseState => ({
		token: "",
		// 版本号
		version: "0.0.2",
		// 当前路径
		activePath: "/",
		// cos前缀
		cosPrefix: "https://sms-1302634640.file.myqcloud.com/cloud-jingzhu/",
		// 菜单列表
		menuList: <INav[]>[],
		// 语言
		language: null,
		// 屏幕断点
		breakPoint: null
	}),
	getters: {
		getMenuByPath: state => {
			return (path: string) => state.menuList.find(item => item.path == path);
		}
	},
	actions: {
		/**
		 * 获取菜单列表
		 */
		getMenuList() {
			this.menuList = nav.list;
		},
		/**
		 * 设置token
		 * @param token
		 */
		setToken(token: string | undefined) {
			this.token = token;
		},
		/**
		 * 设置当前路径
		 * @param token
		 */
		setActivePath(path: string) {
			this.activePath = path;
		}
	},
	persist: {
		enabled: true,
		strategies: [{ paths: ["token", "language"] }]
	}
});
